from fastapi import FastAPI
import dash
from dash import html
from starlette.middleware.wsgi import WSGIMiddleware

# 创建FastAPI实例
app = FastAPI()

# 创建Dash应用程序
dash_app = dash.Dash(url_base_pathname='/dash')
# 在Dash应用程序中创建布局
dash_app.layout = html.Div([
    html.H1('Hello Dash with FastAPI')
])


# 创建FastAPI路由
@app.get('/')
async def read_root():
    return {'Hello': 'FastAPI'}


app.mount("/dash", WSGIMiddleware(dash_app.server))

# 运行应用程序
if __name__ == '__main__':
    import uvicorn

    uvicorn.run(app.servers, host='0.0.0.0', port=8000)
